import os

from flask import Flask, jsonify

# 导入BlogSpider类
app = Flask(__name__)
@app.route('/')
def helo_world():
    return {
        "name":'demo',
        "content":'Hello World!!!@@@@'
    }

@app.route('/next',endpoint='next_word')
def next():
    return {
        "name":'demo',
        "content":'Hello World!!!@@@@'
    }

@app.route('/json')
def get_json():
    return jsonify({
        "name":'demo',
        "content":'Hello World!!!@@@@'
    })

@app.route('/scraper')
def scraper():
    # scrape_data = []
    #
    # def _crawler_result(item, response, spider):
    #     scrape_data.append(dict(item))
    #
    # dispatcher.connect(_crawler_result, signal=signals.item_scraped)
    #
    # @defer.inlineCallbacks
    # def crawl(reactor):
    #     runner = CrawlerRunner()
    #     yield runner.crawl(BlogSpider, start_urls=["https://product.pconline.com.cn/mobile/apple/2359779_detail.html"])
    #     reactor.stop()
    #
    # def run_crawler():
    #     react(crawl)
    #
    # thread = Thread(target=run_crawler)
    # thread.start()
    # thread.join()
    os.system('scrapy crawl test_spider -o articles.json')
    return "jsonify(scrape_data)"

if __name__ == '__main__':
    app.run(port=9527,debug=True)